package entity

import (
	"errors"
	"time"

	"github.com/jinzhu/gorm"
	"shqsoft.cn/pasnj/base"
)

//BASE_LDJS_XM 托管中收导入
type BASE_LDJS_XM struct {
	ID     int       `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	JSID   int       `gorm:"column:JSID"`
	JSNR   string    `gorm:"column:JSNR"`
	JSCP   string    `gorm:"column:JSCP"`
	JSMB   float64   `gorm:"column:JSMB"`
	JSQSR  time.Time `gorm:"column:JSQSR"`
	JSJZR  time.Time `gorm:"column:JSJZR"`
	JSFW   string    `gorm:"column:JSFW"`
	JSFWQT string    `gorm:"column:JSFWQT"`
	JLBZ   string    `gorm:"column:JLBZ"`
	ZYLX   string    `gorm:"column:ZYLX"`
	ZYLXQT string    `gorm:"column:ZYLXQT"`
	JSYS   float64   `gorm:"column:JSYS"`
}

//TableName 经营单位中收导入
func (BASE_LDJS_XM) TableName() string {
	return "T_BASE_LDJS_XM"
}

//BeforeSave 保存前的触发器
func (i *BASE_LDJS_XM) BeforeSave(tx *gorm.DB) (err error) {
	if i.JSQSR.After(i.JSJZR) {
		return errors.New("落实起始日不能大于落实截止日。")
	}
	return
}

// AfterFind 查询后触发器
func (i *BASE_LDJS_XM) AfterFind(tx *gorm.DB) (err error) {
	if i.JSFW == "其他" {
		i.JSFW = i.JSFWQT
	}
	if i.ZYLX == "其他" {
		i.ZYLX = i.ZYLXQT
	}
	return
}

//BASE_LDJS_XMEF 返回结构体
func BASE_LDJS_XMEF() base.EntityFunc {
	return func() interface{} {
		entity := BASE_LDJS_XM{}
		return &entity
	}
}

//BASE_LDJS_XMESF 返回结构体数组
func BASE_LDJS_XMESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []BASE_LDJS_XM
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("BASE_LDJS_XM", base.NewDefaultDao(BASE_LDJS_XMEF(), BASE_LDJS_XMESF(), nil))
}
